unit ConfFormUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, sSkinProvider, sSkinManager, sSpinEdit, sButton,
  sLabel, sEdit, IniFiles, sCheckBox, Registry;

type
  TConfigForm = class(TForm)
    sSkinProvider1: TsSkinProvider;
    sLoginEDT: TsEdit;
    sLabel1: TsLabel;
    sLabel2: TsLabel;
    sPassEDT: TsEdit;
    sButton1: TsButton;
    sLabel3: TsLabel;
    UpdIntSE: TsSpinEdit;
    sLabel4: TsLabel;
    balloonCB: TsCheckBox;
    autostartCB: TsCheckBox;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure sButton1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    conffile:TIniFile;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  ConfigForm: TConfigForm;

implementation

{$R *.dfm}

procedure TConfigForm.FormCreate(Sender: TObject);
begin
  conffile := TIniFile.Create(ExtractFilePath(Application.ExeName)+'ttcab.ini');
end;

procedure TConfigForm.FormShow(Sender: TObject);
begin
  sLoginEDT.Text := conffile.ReadString('main','login','');
  sPassEDT.Text := conffile.ReadString('main','password','');
  UpdIntSE.Value := StrToInt(conffile.ReadString('main','update',''));
  if StrToInt(conffile.ReadString('main','balloon','')) = 1 then
    balloonCB.Checked := true
  else
    balloonCB.Checked := False;
  if StrToInt(conffile.ReadString('main','autostart','')) = 1 then
    autostartCB.Checked := true
  else
    autostartCB.Checked := False;
end;

procedure TConfigForm.sButton1Click(Sender: TObject);
var
h: TRegistry;
begin
  conffile.WriteString('main','login',sLoginEDT.Text);
  conffile.WriteString('main','password',sPassEDT.Text);
  conffile.WriteString('main','update',IntToStr(UpdIntSE.Value));
  if balloonCB.Checked then
    conffile.WriteString('main','balloon','1')
  else
    conffile.WriteString('main','balloon','0');

  if autostartCB.Checked then
    begin
      h := TRegistry.Create;
      with h do
        begin
          RootKey := HKEY_LOCAL_MACHINE;
          OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run', true);
          WriteString('TuronTray', Application.ExeName);
          CloseKey;
          Free;
        end;
      conffile.WriteString('main','autostart','1')
    end
  else
    begin
      h := TRegistry.Create;
      with h do
        begin
          RootKey := HKEY_LOCAL_MACHINE;
          OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run', true);
          DeleteValue('TuronTray');
          CloseKey;
          Free;
        end;
      conffile.WriteString('main','autostart','0')
    end;


end;

procedure TConfigForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caFree;
end;

end.
